package com.sw.resultinfo;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;

/**
 * 统一结果返回实体类
 * @Author howfree
 * @Date 2020/6/29 16:33
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable{
    /**
     * 是否成功
     */
    private boolean flag;
    /**
     * 返回码枚举
     */
    private StatusCode statusCode;
    /**
     * 返回码
     */
    private int code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回数据 - 可以为空
     */
    private T data;

    public Result(boolean flag, StatusCode statusCode) {
        this.flag = flag;
        this.statusCode = statusCode;
        this.code = statusCode.getCode();
        this.message = statusCode.getDesc();
    }

    public Result(boolean flag, StatusCode statusCode,T data) {
        this.flag = flag;
        this.statusCode = statusCode;
        this.code = statusCode.getCode();
        this.message = statusCode.getDesc();
        this.data = data;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public StatusCode getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(StatusCode statusCode) {
        this.statusCode = statusCode;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
